#include "UniformIntDistribution.h"

UniformIntDistribution::UniformIntDistribution(int lowerbound, int upperbound) {
    generator = new boost::random::random_device;
    distribution = new boost::random::uniform_int_distribution<int>(lowerbound, upperbound);
    variate_generator = new boost::variate_generator < boost::random::random_device&, boost::random::uniform_int_distribution<int> > (*generator, *distribution);
}

UniformIntDistribution::~UniformIntDistribution() {
    delete variate_generator;
    delete distribution;
    delete generator;
}

int UniformIntDistribution::Sample() {
    return variate_generator->operator ()();
}

int UniformIntDistribution::min() {
    return distribution->min();
}

int UniformIntDistribution::max() {
    return distribution->max();
}

/**
 * Retorna um inteiro ~ U[lowerbound, upperbound]
 * @param lowerbound limite inferior
 * @param upperbound limite superior
 * @return um inteiro ~U[lowerbound, upperbound]
 */
int UniformIntDistribution::rand(int lowerbound, int upperbound) {
    UniformIntDistribution * obj = new UniformIntDistribution(lowerbound, upperbound);
    int i = obj->Sample();
    delete obj;
    return i;
}
